clear all; close all; clc;

R = 220;
C =33e-12;
L=100e-6;
RC=R*C;



f0=1/(2*pi*sqrt(L*C));
T = 1/ (10000*f0);
t = 0:T:(15*1/f0);
it=length(t);

Uc = nan(1, it);
Ul = nan(1, it);
dUc = nan(1, it);
i = nan(1, it);
di = nan(1, it);

f=f0;
A=[0;1;2;3];

U = nan(length(A), it);
for n = 1:length(A)
      E= A(n)*cos(2*pi*f*t);


%������ ��������� ��������� 
Uc(1)=0; 
i(1)=0;
di(1)=0;
Ul(1)=di(1)*L;



for k = 2:it

    Ul(k)=E(k)-i(k-1)*R-Uc(k-1);
    di(k)=Ul(k)/L;
    i(k)=i(k-1)+di(k-1)*T;
    dUc(k)=i(k)/C;
    Uc(k)=Uc(k-1)+dUc(k)*T;
    
end
U(n,:)=Uc;

Us = U(fix(end/2):end);
    K(j) = (max(Us) - min(Us)) / 2;
end

    
% figure(1);
% plot(t*1e9, [E; U]);
% xlabel('t, ns');
% ylabel('E,U, Volt');
% legend('E(t|A=3)','U(t|A=0)','U(t|A=1)','U(t|A=2)','U(t|A=3)')
% grid on;

figure;
plot(f, 20*log10(K))
xlabel('f, Hz');
ylabel('K, dB');
grid on
figure;
plot(f, K)
xlabel('f, Hz');
ylabel('K');
grid on